package com.igeek.yygh.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.yygh.mapper.HealthyMapper;
import com.igeek.yygh.model.healthy.Healthy;
import com.igeek.yygh.service.HealthyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-22
 */
@Service
public class HealthyServiceImpl extends ServiceImpl<HealthyMapper, Healthy> implements HealthyService {
@Autowired
private HealthyMapper healthyMapper;
    @Override
    public List<Healthy> getlist(Healthy healthy) {
        List<Healthy> getlist1 = healthyMapper.getlist(healthy);
for(Healthy healthy1:getlist1){
    int point =100;
    Integer heart1 = Integer.valueOf(healthy1.getHeart());
    Double sugar1 = Double.valueOf(healthy1.getSugar());
    String[] split = healthy1.getBlood().split("/");
    Integer lowblood = Integer.valueOf(split[0]);
    Integer  heightblood= Integer.valueOf(split[1]);

    if  (heart1>60 && heart1 <85){
    }
    else if ( (heart1>=85 && heart1 <100) || (heart1>55 && heart1 <=60) ){
        point =point -5;
    }else if(heart1>=100 && heart1 <110){
        point=point - 10;
    }else if((heart1>=110 && heart1 <=125) || (heart1>=47 && heart1 <55)){
        point = point -17;
    }else {
        point = point - 22;
    }

    if  (sugar1>4.5 && sugar1 <5.5){
    }
    else if ( (sugar1>3.9 && sugar1 <4.5) || (sugar1>5.5 && sugar1 <6.0) ){
        point =point -5;
    }else if(sugar1>=6.0 && sugar1 <7.0){
        point=point - 10;
    }else if((sugar1>=3.5 && sugar1 <=3.9) || (sugar1>=7.0 && sugar1 <8.0)){
        point = point -17;
    }else {
        point = point - 22;
    }

    if (heightblood<120){
    }
    else if ( heightblood>140 && heightblood <159){
        point =point -5;
    }else if(heightblood>=160 && heightblood <170){
        point=point - 10;
    }else if(heightblood>=170 && heightblood <=179){
        point = point -17;
    }else {
        point = point - 22;
    }
    if (lowblood<90){
    }
    else if ( lowblood>90 && lowblood <99){
        point =point -5;
    }else if(lowblood>=100 && lowblood <105){
        point=point - 10;
    }else if(lowblood>=105 && lowblood <=110){
        point = point -17;
    }else {
        point = point - 22;
    }
    healthy1.setPoint(point);
    if (point <= 100 && point >= 80){
        healthy1.setCondition("优秀");
    }
    else if (point < 80 && point >= 60){
        healthy1.setCondition("正常");
    }
    else if (point < 60 && point >= 40){
        healthy1.setCondition("偏低");
    }
    else if (point < 40 && point >= 20){
        healthy1.setCondition("较差");
    }
    else if (point < 20 && point >= 0){
        healthy1.setCondition("严重");
    }

}

        return getlist1;
    }

    @Override
    public IPage<Healthy> selectUserWithDepartment(Page<Healthy> page, Integer olderId, String name, String startTime, String endTime) {
        IPage<Healthy> healthyIPage = healthyMapper.selectUserWithDepartment(page,olderId,name,startTime,endTime);
        List<Healthy> records = healthyIPage.getRecords();
        return healthyIPage;
    }
}
